<template>
	<myView>
		<u-form :model="model" ref="uForm" >
			<slot></slot>
			<!-- 放底部按钮 -->
			<slot name="bottombtn">
				
				<myBottomBtn title="保存" @confirm="confirm"></myBottomBtn>
				
				
			</slot>
		</u-form>
	</myView>
		
</template>

<script>
	export default {
		name:"myForm",
		props:{
			model: {
				type: Object,
				default () {
					return {}
				}
			},
			rules: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return {
				
			};
		},
		watch: {
			rules: {
				immediate: true,
				deep: true,
				handler(val) {
					this.$nextTick(()=>{
						this.$refs.uForm.setRules(val)
						
					});
					
				}
			}
		},
		methods: {
			async confirm(){
				this.$log(this.$refs.uForm.rules)
				let valid = await this.$refs.uForm.validate();
				this.$log(valid+','+this.model.name);
				if(valid){
					this.$emit('confirm');
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>